//
// Created by xili on 2024/8/7 9:56.
// Go big or go home.
//
#include <vector>
#include <algorithm>

using namespace std;

class Solution {
public:
    int maximumUnits(vector<vector<int>> &boxTypes, int truckSize) {
        int ans = 0;
        sort(boxTypes.begin(), boxTypes.end(), [](vector<int> a, vector<int> b) {
            return a[1] > b[1];
        });
        for (auto &item: boxTypes) {
            while (truckSize) {
                ans += truckSize - item[0] >= 0 ? item[0] * item[1] : truckSize * item[1];
                truckSize -= item[0];
            }
        }
        return ans;
    }
};